// pages/extractRecord/extractRecord.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordList: [],
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var uid = wx.getStorageSync('uid');
    var param = {
      uid: uid,
      page: 1
    };
    app.wxRequest('POST', "Index/withdrawalList", param, (res) => {
      var data = res.data;
      console.log(res)
      that.setData({
        recordList: data
      })
    }, (err) => {
      console.log(err.errMsg)
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that=this;
    var uid = wx.getStorageSync('uid');
    var param = {
      uid: uid,
      page: 1
    };
    app.wxRequest('POST', "Index/withdrawalList", param, (res) => {
      var data = res.data;
      that.setData({
        recordList: data
      })
    }, (err) => {
      console.log(err.errMsg)
    })
    setTimeout(function(){
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },3000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var page =that.data.page;
    var uid = wx.getStorageSync('uid');
    var newPage=parseInt(page) + 1;
    var recordList=that.data.recordList;
    var param = {
      uid: uid,
      page: newPage
    };
    app.wxRequest('POST', "Index/withdrawalList", param, (res) => {
      var data = res.data;
      var code=res.code;
      if(code == 1){
        that.setData({
          recordList: recordList.concat(data),
          page:newPage
        })
      }else{
        wx.showToast({
          title: res.msg,
          icon:"none",
          duration:1500
        })
      }
      
    }, (err) => {
      console.log(err.errMsg)
    })
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})